package com.yuanqi.hnucshop.controller;

import com.yuanqi.hnucshop.entity.User;
import com.yuanqi.hnucshop.service.UserService;
import com.yuanqi.hnucshop.service.ex.ServiceException;
import com.yuanqi.hnucshop.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController extends BaseController{

    @Autowired
    UserService userService;

    @RequestMapping("/register")
    public JsonResult register(String openid, String code) throws ServiceException {

        Boolean aBoolean = userService.verifyUser(openid, code);

        if (aBoolean){
            return new JsonResult(OK);
        }
        return new JsonResult(400, "注册失败");
    }

    @RequestMapping("/checkUser")
    public JsonResult checkUser(String openid){
        User user = userService.selectUser(openid);

        if (user == null) return new JsonResult(400,"用户不存在");

        return new JsonResult(OK);
    }

}
